package com.xlh.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xlh.constant.UserConstant;
import com.xlh.param.UserCreateOrUpParam;
import com.xlh.param.UserListParam;
import com.xlh.vo.UserVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import com.xlh.dao.UserDao;
import com.xlh.entity.UserEntity;
import com.xlh.service.UserService;

import java.util.List;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public List<UserEntity> listUserInfo(String username) {

        List<UserEntity> list = userDao.selectList(username);
        return list;
    }

    @Override
    public IPage<UserVO> list(UserListParam userListParam) {


        return null;
    }

    @Override
    public void create(UserCreateOrUpParam userListParam) {

        UserEntity user = userListParam.convert(userListParam);
        String encodePassword = new BCryptPasswordEncoder().encode(StringUtils.isEmpty(user.getPassword())
                ? UserConstant.INIT_PASSWORD : user.getPassword());
        user.setPassword(encodePassword);
        save(user);
    }

    @Override
    public void update(UserCreateOrUpParam upParam) {




    }

}